package com.crunch.physics;

/**
 * Helps construct category masks.
 */
public class CategoryMask {
	public static final int MASK_NO_CATEGORIES  = 0;
	public static final int MASK_ALL_CATEGORIES = 0xffffffff;

	public static int addCategoryToMask(int mask, int category) {
		if (category < 0 || category >= DynamicPhysicsEntity.CATEGORIES) {
			throw new IllegalArgumentException("Invalid category");
		}

		return mask | (1 << category);
	}

	public static int removeCategoryFromMask(int mask, int category) {
		if (category < 0 || category >= DynamicPhysicsEntity.CATEGORIES) {
			throw new IllegalArgumentException("Invalid category");
		}

		return mask & ~(1 << category);
	}

	public static boolean doesMaskContainCategory(int mask, int category) {
		if (category < 0 || category >= DynamicPhysicsEntity.CATEGORIES) {
			throw new IllegalArgumentException("Invalid category");
		}

		return (mask & (1 << category)) != 0;
	}
}
